import 'package:flutter/material.dart';
import 'bars/home.dart';
import 'bars/category.dart';
import 'bars/setting.dart';
import 'bars/user.dart';

class Bars extends StatefulWidget {
  const Bars({super.key});

  @override
  State<Bars> createState() => _BarsState();
}

class _BarsState extends State<Bars> {
  int _currentIndex = 0;
  final List<Widget> _pages = const [
    Homepage(),
    CategoryPage(),
    SettingPage(),
    // UserPage(),
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          "Flutter App",
          style: TextStyle(color: Colors.white),
        ),
        backgroundColor: Colors.blue,
      ),
      body: _pages[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        fixedColor: Colors.blue, // 选中菜单的颜色
        iconSize: 35, // 底部菜单大小
        currentIndex: _currentIndex, // 选中的菜单
        type: BottomNavigationBarType.fixed, // 如果底部有四个以上的菜单就要配置他
        // 点击菜单触发的方法
        onTap: (index) {
          // 注意
          setState(() {
            _currentIndex = index;
          });
        },
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            label: "首页",
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.category),
            label: "分类",
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.settings),
            label: "设置",
          ),
          // BottomNavigationBarItem(
          //   icon: Icon(Icons.people),
          //   label: "用户",
          // ),
        ],
      ),
    );
  }
}
